import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
//vue3在路由route.js中获取不到仓库pinia中store里面的值
import { createPinia } from 'pinia'
export const pinia = createPinia()
 
export const useCounterStore = defineStore('counter', () => {
  const count1 = ref(0)
  const count = ref(0)
  const first = ref(false)
  const doubleCount = computed(() => count1.value * 2)
  function increment() {
    count1.value++
    count.value++
  }
    const change = ()=>{
      first.value = true
    }   
  return { count1,count, doubleCount, increment,first,change }

},
{
  persist:{
    enable:true,
    storage:window.localStorage,
    key:'user',
    paths:['count','count1']
  }

})

// export const useCounterStore = defineStore('counter',{
//   state: () => {
//     return {
//       count:0
//     }
//   },
//    actions: {
//     increment(){
//       this.count++
//     }
//   },
//    persist:{
//     enable:true,
//     storage:window.sessionStorage,
//     paths:['count']
//    }
 
// })